home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
t_os
/
et
/
src
/
menu.c
< prev
next >
Wrap
Text File
|
1993-07-08
|
10KB
|
401 lines
#include "et.h"
void main(int argc, char *argv[])/*et*/
{
int i, j, font_n, menu_n, menu_i, fdd, ram, col_al;
fdd = ram = menu_i = 0;
custom(&ram, &menu_i, &G_nb.ps_r, &G_f);
while (argc--)
if ((*++argv)[0] == '-') {
i = *++(argv[0]);
switch (i) {
case 'i':
case 'I':
G_nb.ps_r = atoi(++(argv[0]));
break;
case 'm':
case 'M':
menu_i = *++(argv[0]);
break;
case 'v':
set_bit(G_f, f_VIEW);
break;
case 'V':
res_bit(G_f, f_VIEW);
break;
case 'r':
set_bit(G_f, f_RND);
break;
case 'R':
res_bit(G_f, f_RND);
break;
case 's':
case 'S':
res_bit(G_f, f_GPH);
set_bit(G_f, f_SV);
break;
case 't':
case 'T':
res_bit(G_f, f_SV);
set_bit(G_f, f_GPH);
break;
case 'u':
case 'U':
res_bit(G_f, f_SV|f_GPH);
break;
case 'w':
case 'W':
j = *++(argv[0]);
ram = islower(j) ? j - 'a' + 'A' : j;
init_dot(fdd, ram);
break;
case 'x':
set_bit(G_f, f_EXG);
break;
case 'X':
res_bit(G_f, f_EXG);
break;
}
}
init_main(&col_al, &ram, &fdd, &font_n, &menu_n);
init_et();
if (!test_bit(G_f, f_ERR)) {
init_dot(fdd, ram);
menu_i = init_start(menu_i);
switch(menu_i) {
case mn_DEMO:
init_dot(0, 0);
res_bit(G_f, f_RND|f_VIEW|f_EXG);
setjmp(G_jb);
while (test_bit(G_f, f_DEMO)) {
if (test_bit(G_f, f_ABORT))
res_bit(G_f, f_ABORT);
G_pn.demo = P_i[i_KEY_DEMO];
G_pn.key_fp = (char*)P_v[v_VIEW_2];
G_pn.csr_fp = (char*)((int)G_pn.key_fp + (int)P_i[i_SIZE_ICN][0]*10);
G_pn.fp = (char*)((int)G_pn.csr_fp + (int)P_i[i_SIZE_ICN][0]*10);
G_nb.key = G_nb.csr = 0;
load_key(0, 0);
disp_vram();
res_bit(G_f2, (f2_PNA|f2_FONT|f2_MOUSE));
res_bit(G_f, ~(f_VIEW|f_RND|f_EXG|f_SV|f_GPH|f_DEMO));
menu();
if (test_bit(G_f, f_GPH))
res_bit(G_f, f_GPH);
else if (test_bit(G_f, f_SV)) {
res_bit(G_f, f_SV);
set_bit(G_f, f_GPH);
} else {
if (test_bit(G_f, f_VIEW|f_RND))
res_bit(G_f, f_VIEW|f_RND);
else
set_bit(G_f, f_VIEW|f_RND);
if (test_bit(G_f, f_EXG))
res_bit(G_f, f_EXG);
else
set_bit(G_f, f_EXG);
shaff_dot(P_dot[dot_FREE_AREA]);
shaff_dot(P_dot[dot_FREE_SAVE]);
copy_dot(P_dot[dot_FREE_WORK], P_dot[dot_FREE_SAVE]);
set_bit(G_f, f_SV);
}
}
break;
case mn_MAKE:
case mn_REPLAY:
case mn_START:
setjmp(G_jb);
if (!test_bit(G_f, f_ERR)) {
res_bit(G_f, ~(f_VIEW|f_RND|f_EXG|f_SV|f_GPH|f_MAKE|f_REPLAY));
do {
if (test_bit(G_f, f_ABORT))
res_bit(G_f, f_ABORT);
disp_vram();
res_bit(G_f2, (f2_PNA|f2_FONT|f2_MOUSE));
menu();
kill_file(2);
} while (test_bit(G_f, f_REPLAY|f_ABORT) && !test_bit(G_f, f_ERR));
}
break;
defult:
break;
}
}
free_et();
term_et();
term_main(col_al, menu_i, font_n, menu_n);
}
void term_main(int col_al, int menu_i, int font_n, int menu_n)/*et*/
{
FILE *File;
unsigned f;
if (G_nb.current == 16)
;
else if (menu_i == mn_END) {
DEBUG("最大カーソル=", G_nb.max_edge, 10);
#ifdef N_FONT_LEN
#else
DEBUG("N_FONT_LEN=", font_n, 10);
#endif /* N_FONT_LEN */
#ifdef N_MENU_NAME
#else
DEBUG("N_MENU_NAME=", menu_n, 10);
#endif /* N_MENU_NAME */
} else if (!test_bit(G_f, f_ERR) && menu_i != mn_DEMO) {
P_c[c_FILE_KEY][9] = _DD;
P_c[c_FILE_CSR][9] = _DD;
P_c[c_FILE_ICN_KEY][9] = _DD;
P_c[c_FILE_ICN_CSR][9] = _DD;
kill_file(1);
P_c[c_FILE_KEY][9] = '_';
P_c[c_FILE_CSR][9] = '_';
P_c[c_FILE_ICN_KEY][9] = '_';
P_c[c_FILE_ICN_CSR][9] = '_';
kill_file(3);
if ((File = fopen(P_c[c_FILE_REPLAY], "ab")) != NULL) {
fclose(File);
f = f_REPLAY;
File = fopen(P_c[c_FILE_REPLAY], "ab");
fseek(File, 0L, 0);
et_fwrite(&f, sizeof(unsigned), 1, File);
fclose(File);
}
}
if (G_nb.current != 16 && !test_bit(G_f, f_ERR)) {
set_file_i(&P_c[c_FILE_BAK][8], 0);
unlink(P_c[c_FILE_BAK]);
}
MOS_end();
_volume();
goto_current();
_set_console(0x1b, col_al);
_set_console(0xb, 0);
screenterm();
}
void menu()/*et*/
{
int i, j, key, key_i, replay_i, dev_b;
static int file_n = 0;
replay_i = init_menu(&file_n);
key_i = nb_key(G_mv);
dev_b = -1;
do {
key = inkey(GETCH);
if ((i = instring(key, P_i[i_KEY_MOVE], sizeof(int))) != 0) {
res_bit(G_f, f_RR);
j = move_et(i, key_i);
switch(j) {
case _TAB:
exg_et();
break;
case _INS:
break;
case 0:
disp_trace();
break;
}
key_i++;
G_mv[key_i].key = EOK;
if (key_i == 1 || key_i >= MAX_KEY) {
if (key_i == 1) { /* == disp_menu(0, NULL, 0) */
dev_b = -1;
G_nb.mn = set_nb_menu();
draw_edge(P_SET, AFT);
for (i = 2; i; i--, exchange_page()) {
if (i == 1) {
copy_window(P_i[i_WIN_MENU], P_v[v_VRAM], 0x14, POKE);
continue;
}
draw_mode(2, mn_BS, L_WHT);
draw_mode(2, mn_SS, L_WHT);
draw_mode(2, mn_EE, L_WHT);
copy_window(P_i[i_WIN_MENU], P_v[v_VRAM], 0x14, PEEK);
}
draw_edge(P_RES, AFT);
} else {
dev_b = -1;
draw_edge(P_SET, AFT);
disp_menu(0, NULL, 6, 0);
}
} else {
i = N_LAST_DOT * key_i / MAX_KEY;
if (dev_b != i) {
dev_b = i;
draw_edge(P_SET, AFT);
for (i = 2; i; i--, exchange_page())
draw_free(0);
draw_edge(P_RES, AFT);
}
}
} else {
key = sub_menu(key, &file_n);
key_i = nb_key(G_mv);
}
} while (key != S_ESC);
term_menu(file_n, replay_i);
}
void term_menu(int file_n, int replay_i)/*et*/
{
FILE *File, *Temp;
int replay_n;
if (!test_bit(G_f, f_DEMO)) {
copy_window(P_i[i_WIN_VIEW], P_v[v_VIEW_0], 0x120, PEEK);
if (!test_bit(G_f, f_REPLAY|f_MAKE)) {
File = fopen(P_c[c_FILE_REPLAY], "ab");
fseek(File, replay_i, 0);
Temp = fopen(P_c[c_FILE_ET_TEMP], "rb");
fseek(Temp, 0L, 2);
replay_i = ftell(Temp);
fseek(Temp, 0L, 0);
copy_file(File, Temp, replay_i);
fclose(Temp);
replay_n = ftell(File);
fclose(File);
}
if (test_bit(G_f, f_REPLAY))
kill_file(1);
else {
copy_buffer(6, STORE, &file_n, replay_n);
if (test_bit(G_f, f_MAKE)) {
res_bit(G_f, f_MAKE);
set_bit(G_f, f_ABORT);
}
}
}
}
int sub_menu(int key, int *file_n_p)/*et*/
{
int i, j, menu_i;
menu_i = (find_key(key))->n;
switch(menu_i) {
case mn_ESC:
key = end_menu(menu_i);
case mn_S_ESC:
break;
case mn_SS:
save(menu_i, file_n_p);
break;
case mn_LL:
load(menu_i, file_n_p);
break;
case mn_CC:
save_key(-1);
cursol(menu_i);
break;
case mn_EE:
case mn_S_EE:
save_key(-1);
set_bit(G_f, f_EE);
j = menu_i == mn_EE;
if (!j)
menu_i = mn_EE;
if (test_bit(G_f, f_NN))
j = !j;
enter(menu_i, j);
res_bit(G_f, f_EE);
break;
case mn_RR:
case mn_S_RR:
stereo(menu_i);
break;
case mn_FF:
save_key(-1);
font(menu_i);
break;
case mn_POS:
if (test_bit(G_f, f_VIEW)) {
if (test_bit(G_f, f_SV|f_GPH))
G_pn.range_lt = G_pn.range_rt = NULL;
else
G_pn.range = NULL;
res_bit(G_f, f_VIEW);
draw_edge(P_SET, AFT);
for (i = 2; i; i--, exchange_page())
for (j = -4; j <= -1; j++)
cls_frame(P_i[i_WIN_VIEW], j, H_WHT, P_RES);
draw_edge(P_RES, AFT);
} else {
set_bit(G_f, f_VIEW);
if (test_bit(G_f, f_SV|f_GPH)) {
cul_edge(G_et, G_edge, G_nb.edge, _LT, 0);
cul_edge(G_et, G_bf.edge, G_nb.edge, _RT, 0);
} else
cul_edge(G_et, G_edge, G_nb.edge, 0, 0);
exchange_page();
draw_edge(P_RES, AFT);
}
break;
case mn_RND:
if (test_bit(G_f, f_RND))
res_bit(G_f, f_RND);
else
set_bit(G_f, f_RND);
shaff_dot(P_dot[dot_FREE_AREA]);
shaff_dot(P_dot[dot_FREE_SAVE]);
copy_dot(P_dot[dot_FREE_WORK], P_dot[dot_FREE_SAVE]);
draw_edge(P_SET, AFT);
paint_free(2);
copy_window(P_i[i_WIN_VRAM], P_v[v_VRAM], 0x14, PEEK);
exchange_page();
copy_window(P_i[i_WIN_VRAM], P_v[v_VRAM], 0x14, POKE);
exchange_page();
draw_edge(P_RES, AFT);
break;
case mn_AA:
case mn_NN:
case mn_OO:
case mn_BAR:
trace(menu_i);
break;
case mn_PP:
case mn_DD:
case mn_XX:
case mn_YY:
case mn_ZZ:
case mn_GG:
save_key(-1);
change(menu_i);
break;
case mn_AT:
change(menu_i);
break;
case mn_WW:
set_bit(G_f, f_WW);
if (test_bit(G_f, f_AA) && nb_key(G_mv))
set_ww(menu_i);
else
change(menu_i);
res_bit(G_f, f_WW);
break;
case mn_TT:
save_key(-1);
copy_pna(menu_i);
break;
case mn_S_BS:
save_key(-1);
clear(menu_i);
break;
case mn_BS:
delete(menu_i);
break;
}
return(key);
}
int end_menu(int menu_i)/*et*/
{
int key;
disp_menu(menu_i, NULL, 11, 0);
while ((key = inkey(WINK)) == 0)
;
if (key == _ESC)
disp_menu(menu_i, NULL, 6, 0);
else
key = S_ESC;
return(key);
}